﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionEngine
{
    /// <summary>
    /// 操作符操作实现
    /// </summary>
    public class OperatorHandler : ExpressionHandler
    {
        #region 计算操作符，包括函数，有效性验证
        protected bool validate(OperationSymbol oper)
        {
            if (oper == null || oper.Identifier == null || oper.Operands.Count != oper.Dimension)
                return false;

            return true;
        }
        #endregion

        /// <summary>
        /// 操作符处理
        /// </summary>
        /// <param name="oper"></param>
        /// <returns></returns>
        public virtual Variable operate(OperationSymbol oper)
        {
            throw new Exception("找不到合适的操作符处理器");
        }

        #region 验证参数类型
        protected DataType ValidateVarDataType(List<Variable> dictionary)
        {
            DataType dataType = dictionary.First().ValueType;
            foreach (Variable item in dictionary)
            {
                if (item.ValueType != dataType
                    && item.ValueType != DataType.FLOAT
                    && item.ValueType != DataType.INT
                    && item.ValueType != DataType.DOUBLE)
                    throw new Exception("参数类型不一致");
            }

            return dataType;
        }
        #endregion
    }
}
